package org.oslims.client.view.impl;

import org.oslims.client.view.UploadView;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;

public class UploadViewImpl extends BaseViewImpl implements UploadView {

	FormPanel formPanel = new FormPanel();

	public UploadViewImpl() {
		formPanel.setAction("/oslims/uploadService");
		formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
		formPanel.setMethod(FormPanel.METHOD_POST);

		VerticalPanel vp = new VerticalPanel();
		formPanel.setWidget(vp);

		FileUpload upload = new FileUpload();
		upload.setName("uploadWidget");

		vp.add(upload);

		Hidden requestId = new Hidden();
		requestId.setName("requestId");
		requestId.setValue("1");
		vp.add(requestId);

		Hidden labStaffId = new Hidden();
		labStaffId.setName("labStaffId");
		labStaffId.setValue("3");
		vp.add(labStaffId);

		// Add a 'submit' button.
		vp.add(new Button("Submit", new ClickHandler() {
			public void onClick(ClickEvent event) {
				formPanel.submit();
			}
		}));

		formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {

			@Override
			public void onSubmitComplete(SubmitCompleteEvent arg0) {
				Window.alert(arg0.getResults());
			}
		});

		initWidget(formPanel);

	}
}
